package com.hirsi.core.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.json.JSONUtil;
import lombok.Data;

public class ConfigUtil {

    private static String CONFIG_PATH = "/config/config.json";

    private static Config config;

    public static Config getConfig() {
        if (config == null) init();
        return config;
    }

    public static void init() {
        if (System.getProperty("os.name").contains("Windows")) CONFIG_PATH = "D:" + CONFIG_PATH;
        if (FileUtil.exist(CONFIG_PATH)) {
            config = JSONUtil.toBean(FileUtil.readString(CONFIG_PATH, CharsetUtil.UTF_8), Config.class);
        } else {
            config = new Config();
            FileUtil.writeString(JSONUtil.toJsonStr(config), CONFIG_PATH, CharsetUtil.UTF_8);
        }
    }

    public static void main(String[] args) {
        System.err.println(System.getProperty("os.name"));
    }

    @Data
    public static class Config {

        private String password = "123456";

        private String volume = "3G";

        private Integer rr = 5;
    }
}
